package org.anupta.realm.server.realm.client;

import org.anupta.realm.server.realm.packet.account.AccessServer;
import org.anupta.realm.server.realm.packet.account.QueueAccount;
import org.anupta.realm.server.realm.packet.account.ServerList;
import org.anupta.realm.server.realm.packet.login.Login;
import org.anupta.realm.server.realm.packet.login.Version;
import org.anupta.realm.server.realm.packet.other.ConnectionError;

public class RealmParser {
	private RealmClient client = null;
	private String hash = null;
	
	public RealmParser(RealmClient client,String hashKey){
		setClient(client);
		setHash(hashKey);
	}
	
	public void parse(String message){
		switch(client.getState()){
		case VERSION:
			new Version(client, message);
			break;
		case LOGIN:
			if(!message.contains("\n")){
				new ConnectionError(client);
				return;
			}
			new Login(client,message);
			break;
		case GAMESERVER:
			switch(message.charAt(0)){
			case 'A':
				switch(message.charAt(1)){
				case 'f':
					//TODO:Queue System
					new QueueAccount(client);
					break;
				case 'x':
					new ServerList(client);
					break;
				case 'X':
					new AccessServer(client,message);
					break;
				default:
					client.send("BN");
					break;
				}
				break;
			}
			break;
		}
	}

	public String getHash() {
		return hash;
	}

	public void setHash(String hash) {
		this.hash = hash;
	}
	
	private void setClient(RealmClient client){
		this.client = client;
	}
}
